﻿

using System;
using System.Collections.Generic;
using System.Security.Principal;
using System.Threading.Tasks;
using Autofac.Core;
using iTextSharp.text;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WaterCloud.Code;
using WaterCloud.Domain;
using WaterCloud.Domain.Entity.STZBManage;
using WaterCloud.Domain.Entity.STZBManage.Request;
using WaterCloud.Domain.SystemManage;
using WaterCloud.Service.STZBManage;
using WaterCloud.Service.SystemManage;

namespace WaterCloud.Web.Controllers.Api
{
    /// <summary>
    /// 率土之滨账号接口
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [LoginFilter] //验证是否登录
    public class AccountController : ControllerBase
    {
        public STZB_AccountService _accountService { get; set; }

        public WeaponsInfo_Service _weaponsInfo_Service { get; set; }

        /// <summary>
        /// 添加账号数据接口
        /// </summary>
        /// <param name="account">参数数据集合</param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous] //不需要授权
        public async Task<AlwaysResult> Add_Account([FromBody] List<Account_Request> account)
        {
            try
            {
                await _accountService.Add_Account(account);
                return new AlwaysResult { state = ResultType.success.ToString(), message = "操作成功" };
            }
            catch (Exception ex)
            {
                return new AlwaysResult { state = ResultType.error.ToString(), message = $"操作失败：{ex.Message}" };
            }
        }

        /// <summary>
        /// 获取账号列表  
        /// </summary>
        /// <param name="state">账号状态 1:试师、2:征服</param>
        /// <param name="sell_state">出售状态 1:公示期、2:可购买</param>
        /// <param name="orderColume">排序字段 默认：CreateTime</param>
        /// <param name="order">排序方式 默认：Desc</param>
        /// <param name="page">页数</param>
        /// <param name="limit">每页显示条数 默认10条</param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous] //不授权
        public async Task<SqlSugarDataResult<Account>> GetTable(int state, int sell_state, string orderColume = "CreateTime", string order = "Desc", int page = 1, int limit = 10)
        {
            return await _accountService.GetTable(state, sell_state);
        }

        /// <summary>
        /// 添加武器信息
        /// </summary>
        /// <param name="weaponsInfo">信息</param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous] //不需要授权
        public async Task<AlwaysResult> Add_WeaponsInfo([FromBody] WeaponsInfo weaponsInfo)
        {
            try
            {
                await _weaponsInfo_Service.Add_WeaponsInfo(weaponsInfo);
                return new AlwaysResult { state = ResultType.success.ToString(), message = "操作成功" };
            }
            catch (Exception ex)
            {
                return new AlwaysResult { state = ResultType.error.ToString(), message = "操作失败" };
            }
        }


        /// <summary>
        /// 批量添加武器信息
        /// </summary>
        /// <param name="lists">数据集合</param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous] //不需要授权
        public async Task<AlwaysResult> AddList_WeaponsInfo([FromBody] List<WeaponsInfo> lists)
        {
            try
            {
                await _weaponsInfo_Service.AddList_WeaponsInfo(lists);
                return new AlwaysResult { state = ResultType.success.ToString(), message = "操作成功" };
            }
            catch (Exception ex)
            {
                return new AlwaysResult { state = ResultType.error.ToString(), message = "操作失败" };
            }
        }
    }
}
